package me.yiyou.meihua.utils

import me.yiyou.meihua.data.BaGuaImage
import me.yiyou.meihua.data.LunarDate

/**
 * 获取梅花易数上卦,卦数
 */
fun getMeiHuaShang(date: LunarDate): Int {
    return (date.year + date.month + date.day) % 8
}

/**
 * 获取梅花易数下卦,卦数
 */
fun getMeiHuaXia(date: LunarDate): Int {
    return (date.year + date.month + date.day + date.hour) % 8
}

/**
 * 梅花易数,取动爻
 */
fun getMeiHuaDongYao(date: LunarDate): Int {
    val value = (date.year + date.month + date.day + date.hour) % 6
    if (value == 0){
        return 6
    }else{
        return value
    }
}

/**
 * 获取卦象名
 */
fun getGuaXiangName(value: Int): String {
    return when (value) {
        1 -> "乾"
        2 -> "兑"
        3 -> "离"
        4 -> "震"
        5 -> "巽"
        6 -> "坎"
        7 -> "艮"
        0 -> "坤"
        else -> "unKnow"
    }
}

/**
 * 根据卦象图获取卦名(上卦)
 */
fun getGuaNameByImgShang(baGuaImage: BaGuaImage): String {
    var text = ""
    if (baGuaImage.six == true && baGuaImage.five == true && baGuaImage.four == true) {
        text = "乾(金)"
    }
    if (!baGuaImage.six == true && baGuaImage.five == true && baGuaImage.four == true) {
        text = "兑(金)"
    }
    if (baGuaImage.six == true && !baGuaImage.five == true && baGuaImage.four == true) {
        text = "离(火)"
    }
    if (!baGuaImage.six == true && !baGuaImage.five == true && baGuaImage.four == true) {
        text = "震(木)"
    }
    if (baGuaImage.six == true && baGuaImage.five == true && !baGuaImage.four == true) {
        text = "巽(木)"
    }
    if (!baGuaImage.six == true && baGuaImage.five == true && !baGuaImage.four == true) {
        text = "坎(水)"
    }
    if (baGuaImage.six == true && !baGuaImage.five == true && !baGuaImage.four == true) {
        text = "艮(土)"
    }
    if (!baGuaImage.six == true && !baGuaImage.five == true && !baGuaImage.four == true) {
        text = "坤(土)"
    }
    return text
}

/**
 * 根据卦象图获取卦名(下卦)
 */
fun getGuaNameByImgXia(baGuaImage: BaGuaImage): String {
    var text = ""
    if (baGuaImage.three == true && baGuaImage.two == true && baGuaImage.one == true) {
        text = "乾(金)"
    }
    if (!baGuaImage.three == true && baGuaImage.two == true && baGuaImage.one == true) {
        text = "兑(金)"
    }
    if (baGuaImage.three == true && !baGuaImage.two == true && baGuaImage.one == true) {
        text = "离(火)"
    }
    if (!baGuaImage.three == true && !baGuaImage.two == true && baGuaImage.one == true) {
        text = "震(木)"
    }
    if (baGuaImage.three == true && baGuaImage.two == true && !baGuaImage.one == true) {
        text = "巽(木)"
    }
    if (!baGuaImage.three == true && baGuaImage.two == true && !baGuaImage.one == true) {
        text = "坎(水)"
    }
    if (baGuaImage.three == true && !baGuaImage.two == true && !baGuaImage.one == true) {
        text = "艮(土)"
    }
    if (!baGuaImage.three == true && !baGuaImage.two == true && !baGuaImage.one == true) {
        text = "坤(土)"
    }
    return text
}